
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/12/2009
 * PROJECT:             MCWEBSTIE
 * PURPOSE:             websiteAdResourceDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteAdResourceDAL
    {
        #region  Properties
		 
		public static string FIELD_ADID = "AdID";  
		public static string FIELD_RESOURCEID = "ResourceID"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteAdResource
        /// </summary>
        /// <param name="ResourceID">Primary Keys</param>
        /// <returns>Collection of websiteAdResourceInfo</returns>
        public static websiteAdResourceInfo SelectOne(int ResourceID)
        {
            websiteAdResourceInfo _websiteAdResourceInfo = new websiteAdResourceInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteAdResourceSelectOne", ResourceID);
                if (dr.Read())
                    setwebsiteAdResourceInfo(dr, ref _websiteAdResourceInfo);
                return _websiteAdResourceInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteAdResource
        /// </summary>
        /// <returns>Collection of websiteAdResourceInfo</returns>
        public static List<websiteAdResourceInfo> SelectAll()
        {
            List<websiteAdResourceInfo> lstwebsiteAdResource = new List<websiteAdResourceInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteAdResourceSelectAll");
                setListwebsiteAdResourceInfo(ref dr, ref lstwebsiteAdResource);
                return lstwebsiteAdResource;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteAdResourcenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteAdResourceInfo</returns>
        public static List<websiteAdResourceInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteAdResourceInfo> lstwebsiteAdResource = new List<websiteAdResourceInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteAdResourceSelectByFilters");
                setListwebsiteAdResourceInfo(ref dr, ref lstwebsiteAdResource);
                return lstwebsiteAdResource;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteAdResource
        /// </summary>
        /// <param name="websiteAdResourceInfo">Entity of websiteAdResource</param>
        /// <returns>error code</returns>
        public static int Insert(websiteAdResourceInfo _websiteAdResourceInfo)
        {
           try
            {
               int InsertedAdResource =Convert.ToInt32( SqlHelper.ExecuteScalar(ConnectionString, "sp_mc_websiteAdResourceInsert", 
											_websiteAdResourceInfo.AdID, _websiteAdResourceInfo.ResourceID));

               return InsertedAdResource;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteAdResource
        /// </summary>
        /// <param name="websiteAdResourceInfo">Entity of websiteAdResource</param>
        /// <returns>error code</returns>
        public static int Update(websiteAdResourceInfo _websiteAdResourceInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteAdResourceUpdate"
											, _websiteAdResourceInfo.AdID
											, _websiteAdResourceInfo.ResourceID
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="ResourceID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int ResourceID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteAdResourceDelete", ResourceID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteAdResourceInfo(ref SqlDataReader dr, ref List<websiteAdResourceInfo> lstwebsiteAdResource)
        {
            websiteAdResourceInfo _websiteAdResourceInfo = null;
            while (dr.Read())
            {
                _websiteAdResourceInfo = new websiteAdResourceInfo();
                setwebsiteAdResourceInfo(dr, ref _websiteAdResourceInfo);
                lstwebsiteAdResource.Add(_websiteAdResourceInfo);
            }
        }

        private static void setwebsiteAdResourceInfo(SqlDataReader dr, ref websiteAdResourceInfo _websiteAdResourceInfo)
        {
			_websiteAdResourceInfo.AdID = dr[websiteAdResourceDAL.FIELD_ADID] != DBNull.Value ? Convert.ToInt32(dr[websiteAdResourceDAL.FIELD_ADID]) : 0;
			_websiteAdResourceInfo.ResourceID = dr[websiteAdResourceDAL.FIELD_RESOURCEID] != DBNull.Value ? Convert.ToInt32(dr[websiteAdResourceDAL.FIELD_RESOURCEID]) : 0;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteAdResource]";

        #endregion
    }
}

		